{include file="header/index" /}
<style>
	.engineers{
		width: 180px;
		height: 25px;
		border: 1px solid #D9D9D9;
		border-radius: 3px;
		padding: 0 10px;
		font-size: 12px;
		color: gray;
	}
	.engineers_box{
		display: none;
	}
</style>
<!-- 加载动画 -->
<div class="spiner-example hides" style="position: fixed; top: 30px; left:50%; margin-left: -35px">
	<div class="sk-spinner sk-spinner-three-bounce">
		<div class="sk-bounce1"></div>
		<div class="sk-bounce2"></div>
		<div class="sk-bounce3"></div>
	</div>
</div>

		<div class="container bgwhite">
			<h2 class="container-title ">新增工单</h2>

			<form class="form-horizontal" enctype="multipart/form-data" action="{:url('/administrative/workorder/addto')}" method="post">
				<div class="mb40 woekorder">
					<h3 class="mt30 fs14 col-333">用户信息</h3>
					<div class="clearfix">
						<p class="mt20 mb20 fl">
							<label class="addEnginerr-title">用户</label>
							<input onclick="openModel(1)" onchange="province_()" class="no-input" type="text" value="" name="_username" readonly="readonly" placeholder="点击选择"  />
							<i class="col-red">*</i>
						</p>
						<!--隐藏域，用来装选中用户的id-->
						<input type="hidden" id="user_id" name="user_id" value="" />
						<p class="mt20 mb20 fl">
							<label class="addEnginerr-title">用户电话</label>
							<input type="text" value="" name="telphone" readonly="readonly" />
							<i class="col-red">*</i>
						</p>
						<p class="mt20 mb20 fl">
							<label class="addEnginerr-title">合同编号</label>
							<input onclick="openModels(1)" class="no-input" type="text" value="" name="contract_no" readonly="readonly" placeholder="点击选择" />
							<i class="col-red">*</i>
						</p>
						<!--隐藏域，用来装选中合同的id-->
						<input type="hidden" id="contract_id" name="contract_id" value="" />
						<p class="mt20 mb20 fl">
							<label class="addEnginerr-title">装机时间</label>
							<input type="text" value="" name="installed_time" id="installedTime" readonly="readonly" />
						</p>
						<p class="mt20 mb20 fl">
							<label class="addEnginerr-title">身份证号</label>
							<input type="text" value="" name="id_card" readonly="readonly" />
							<i class="col-red">*</i>
						</p>
						<p class="mt20 mb20 fl">
							<label class="addEnginerr-title">续费周期</label>
							<input class="col-red" type="text" value="" name="renew_date" id="renewalTime" readonly="readonly" />
						</p>
						<p class="mt20 mb20 fl">
							<label class="addEnginerr-title">联系人</label>
							<input type="text" value="" name="contacts" id="contacts_" />
							<i class="col-red">*</i>
						</p>
						<p class="mt20 mb20 fl">
							<label class="addEnginerr-title">到期时间</label>
							<input class="col-red" type="text" value="" name="exire_date" id="exire_date_" readonly="readonly" />
						</p>
						<p class="mt20 mb20 fl">
							<label class="addEnginerr-title">联系电话</label>
							<input type="text" value="" id="contact_number_" name="contact_number" />
							<i class="col-red">*</i>
						</p>
						<p class="mt20 mb20 fl engineers_box">
							<label class="addEnginerr-title">讲解人</label>
							<select name="engineers" id="" class="engineers">
								<option value="">请选择讲解人</option>
								{volist name="engineers" id="en"}
								<option value="{$en.engineers_id}">{$en.engineers_name}{if condition="$en.engineers_status == 1"}[冻结]{/if}</option>
								{/volist}
							</select>
							<input type="hidden" name="is_explain" id="is_explain" value="2">
							<i class="col-red">*</i>
						</p>
					</div>

				</div>
				<div>
					<h3 class="mt30 fs14 col-333">基本信息</h3>

					<p class="mt20 mb20">
						<label class="addEnginerr-title">业务类型</label>
						<select class="workOrder-select" name="businessid" onchange="ShiftSelect(this)" id="business_id">

							<option value="0">请选择</option>
							{foreach $type as $k=>$v}
							<option value="{$k}">{$v}</option>
							{/foreach}

						</select>
						<i class="col-red">*</i>
					</p>


					  	<!--默认为隐藏，选着移机会弹出-->
					<div class="ShiftCenter hides">
						<p class="mt20 mb20 clearfix">
							<label class="addEnginerr-title"></label>
							<span class="mr20 fl"><input class="fl" type="radio" name="shift" value="5">移机</span>
							<span class="mr20 fl"><input class="fl" type="radio" name="shift" value="9">移机拆</span>
							<span class="mr20 fl"><input class="fl" type="radio" name="shift" value="10">移机装</span>
						</p>

						<p class="mt20 mb20 clearfix">
							<label class="addEnginerr-title">是否是同一用户</label>
							<select class="workOrder-select" name="isuser" id="isuser" onchange="test()">
								<option value="0">请选择</option>
								<option value="1">是</option>
								<option value="2">否</option>
							</select>
							<i class="col-red">*</i>
						</p>

						<p class="mt20 mb20">
							<!--用户三级联动地址-->
							<input type="hidden" name="moveprovince" value="" />
							<input type="hidden" name="movecity" value="" />
							<input type="hidden" name="movearea" value="" />
							<label class="addEnginerr-title">移机区域</label>
							<select class="addEnginerr-select" id="province" name="province_id" onchange="province__()">
								<option value="">--选择省--</option>
							{volist name="province" id="p"}
								<option value="{$p.id}" data="{$p.id}" {if condition="$p.id == $data.province_id"}selected{/if}>{$p.area_name}</option>
							{/volist}
							</select>
							<select class="addEnginerr-select" id="city" name="city_id" onchange="city__()">
								<option value="">--选择市--</option>
							{volist name="city" id="c"}
								<option value="{$c.id}" data="{$c.id}" {if condition="$c.id == $data.city_id"}selected{/if}>{$c.area_name}</option>
							{/volist}
							</select>
							<select class="addEnginerr-select" id="area" name="area_id" onchange="area__()">
								<option value="">--选择区县--</option>
							{volist name="area" id="a"}
								<option value="{$a.id}" data="{$a.id}" {if condition="$a.id == $data.area_id"}selected{/if}>{$a.area_name}</option>
							{/volist}
							</select>
							<i class="col-red">*</i>
						</p>

						<p class="mt20 mb20">
							<label class="addEnginerr-title">详细地址</label>
							<input id="addressDetailss" class="addEnginerr-input" type="text" value="" name="service_address" placeholder="请输入详细地址"  />
							<i class="col-red">*</i>
						</p>

					</div>

					<div class="ShiftCenters hides">
						<p class="mt20 mb20">
							<label class="addEnginerr-title">装机设备+设备编号</label>
							<select class="workOrder-select" id="equipments_name" name="equipmentsname">
								<option value="">请选择</option>
							</select>
							<i class="col-red">*</i>
						</p>

					</div>


					<!--默认为显示，选着移机时是同一用户会隐藏-->
					<div class="ShiftCenterss">
					<p class="mt20 mb20 relative">
						<label class="addEnginerr-title">费用</label>
						<input class="workOrder-input" type="text" value="" name="combo_money" id="combo_money" placeholder="￥0.00" maxlength="11" onkeyup="value=value.replace(/[^\d]/g,'')" />
						<span class="fs12 col-333 absolute" style="left: 235px;top: 5px;">元</span>
						<i class="col-red">*</i>
					</p>

					<p class="mt20 mb20">
						<!--用户三级联动地址-->
						<input type="hidden" name="userprovince" value="" />
						<input type="hidden" name="usercity" value="" />
						<input type="hidden" name="userarea" value="" />
						<label class="addEnginerr-title">用户地址</label>
						<select class="addEnginerr-select" id="_province" name="province_code" onchange="province_()">
								<option value="">--选择省--</option>
							{volist name="province" id="p"}
								<option value="{$p.id}" data="{$p.id}" {if condition="($p.id == $data.province_id)"}selected{/if}>{$p.area_name}</option>
							{/volist}
						</select>
						<select class="addEnginerr-select" id="_city" name="city_code" onchange="city_()">
								<option value="">--选择市--</option>
							{volist name="city" id="c"}
								{if condition='(isset($data) AND ($c.id == $data.city_id))'}
								<option value="{$c.id}" data="{$c.id}" {if condition="($c.id == $data.city_id)"}selected{/if}>{$c.area_name}</option>
								{/if}
							{/volist}
						</select>
						<select class="addEnginerr-select" id="_area" name="area_code" onchange="area_()">
								<option value="">--选择区/县--</option>
							{volist name="area" id="a"}
								<option value="{$a.id}" data="{$a.id}" {if condition="$a.id eq $data.area_id"}selected{/if}>{$a.area_name}</option>
							{/volist}
						</select>
						<i class="col-red">*</i>
					</p>
					<p class="mt20 mb20">
						<label class="addEnginerr-title">详细地址</label>
						<input id="addressDetail" class="addEnginerr-input" type="text" value="" name="user_address" placeholder="请输入详细地址" />
						<i class="col-red">*</i>
					</p>
				</div>
					<p class="mt20 mb20 relative">
						<label class="addEnginerr-title">备注</label>
						<textarea class="addEnginerr-textarea" maxlength="500" name="remarks"></textarea>
						<span class="absolute txtNum_tis">500字以内</span>
					</p>
				</div>
				<p class="engineer-Btn">
					<input type="submit" id="submit" class="engineer-PreBtn" value="保存" />
					<!--<button class="engineer-PreBtn"  type="button">保存</button>-->
					<a href="javascript:(0)" class="engineer-ResetBtn" onclick="reset()">重置</a>
					<a href="javascript:(0)" class="engineer-RuterBtn" onclick="window.history.go(-1);">返回</a>
				</p>
			</form>
		</div>
		<input type="hidden" id="sProvince" onchange="sProvince()">
		<input type="hidden" id="sCity">
		<input type="hidden" id="sArea">
		<script>
            window.onbeforeunload = function()
            {
                //  这是用来设定一个时间, 时间到了, 就会执行一个指定的 method。
                setTimeout(onunloadcancel, 10);
                return "真的离开?";
            }
            window.onunloadcancel = function()
            {
                // alert("取消离开");
            }




		// 选中合同后执行，获取设备信息
		function equipmentssss(contract_id){
            if ($("#business_id option:selected").val() != 3) {
                if ($("#equipments_name").val() == '') {
                    // 发送ajax请求，获取装机设备跟设备编号
					$.getJSON("{:url('/administrative/workorder/getequipments')}", {contract_id: contract_id}, function (data) {
						$("#equipments_name").html('');
						var str = '<option value="">请选择</option>';
						$.each(data, function (k, v) {
							str += '<option value="' + v.id + '">' + v.equipments_name + '---' + v.equipments_number + '</option>';
						});
						$("#equipments_name").html(str);
					});
                }
            }
		}


			// 判断数据是否有值
			$("#submit").click(function(){
                if ($("#business_id").val() == 5) {
                    if ($("#province").val() == '') {
                        layer.msg('请选择移机地址省', {icon: 0});
                        return false;
                    }
                    if ($("#city").val() == '') {
                        layer.msg('请选择移机地址市', {icon: 0});
                        return false;
                    }
                    if ($("#area").val() == '') {
                        layer.msg('请选择移机地址区', {icon: 0});
                        return false;
                    }
                    if ($("input[name='_username']").val() == '') {
                        layer.msg('用户不能为空', {icon: 0});
                        return false;
                    }
                    if ($("input[name='telphone']").val() == '') {
                        layer.msg('用户电话不能为空', {icon: 0});
                        return false;
                    }
                    if ($("input[name='id_card']").val() == '') {
                        layer.msg('身份证不能为空', {icon: 0});
                        return false;
                    }
                    if ($("input[name='contacts']").val() == '') {
                        layer.msg('联系人不能为空', {icon: 0});
                        return false;
                    }
                    if ($("input[name='contact_number']").val() == '') {
                        layer.msg('联系电话不能为空', {icon: 0});
                        return false;
                    }
                    if ($("#business_id").val() == 0) {
                        layer.msg('请选择业务类型', {icon: 0});
                        return false;
                    }
                    if ($("#business_id").val() != 3) {
                        if ($("input[name='contract_no']").val() == '') {
                            layer.msg('合同信息不能为空', {icon: 0});
                            return false;
                        }
                    }
                    if ($("#business_id").val() != 3) {
                        if ($("#equipments_name").val() == '') {
                            layer.msg('装机设备+设备编号不能为空', {icon: 0});
                            return false;
                        }
                    }
                    if ($("#combo_money").val() == '') {
                        layer.msg('费用不能空', {icon: 0});
                        return false;
                    }
                    if ($("#addressDetailss").val() == '') {
                        layer.msg('移机详细地址不能为空', {icon: 0});
                        return false;
                    }
                    var isuser = $("#isuser option:selected").val();
                    if(isuser == 2){
                        if ($("#_province").val() == '') {
                            layer.msg('请选择用户地址省', {icon: 0});
                            return false;
                        }
                        if ($("#_city").val() == '') {
                            layer.msg('请选择用户地址市', {icon: 0});
                            return false;
                        }
                        if ($("#_area").val() == '') {
                            layer.msg('请选择用户地址区', {icon: 0});
                            return false;
                        }
                        if ($("#addressDetail").val() == '') {
                            layer.msg('服务详细地址不能为空', {icon: 0});
                            return false;
                        }
				  }
                }else{
                    if ($("#is_explain").val() == 1 && $("select[name='engineers'] option:selected").val() == ''){
                        layer.msg('合同存在讲解，请选择讲解人', {icon: 0});
                        return false;
                    }
					if ($("input[name='_username']").val() == '') {
						layer.msg('用户不能为空', {icon: 0});
						return false;
					}
					if ($("input[name='telphone']").val() == '') {
						layer.msg('用户电话不能为空', {icon: 0});
						return false;
					}
					if ($("input[name='id_card']").val() == '') {
						layer.msg('身份证不能为空', {icon: 0});
						return false;
					}
					if ($("input[name='contacts']").val() == '') {
						layer.msg('联系人不能为空', {icon: 0});
						return false;
					}
					if ($("input[name='contact_number']").val() == '') {
						layer.msg('联系电话不能为空', {icon: 0});
						return false;
					}
					if ($("#business_id").val() == 0) {
						layer.msg('请选择业务类型', {icon: 0});
						return false;
					}
					if ($("#business_id").val() != 3) {
						if ($("input[name='contract_no']").val() == '') {
							layer.msg('合同信息不能为空', {icon: 0});
							return false;
						}
					}
					if ($("#business_id").val() != 3) {
						if ($("#equipments_name").val() == '') {
							layer.msg('装机设备+设备编号不能为空', {icon: 0});
							return false;
						}
					}
					if ($("#combo_money").val() == '') {
						layer.msg('费用不能空', {icon: 0});
						return false;
					}
					if ($("#_province").val() == '') {
						layer.msg('请选择用户地址省', {icon: 0});
						return false;
					}
                    if ($("#_city").val() == '') {
                        layer.msg('请选择用户地址市', {icon: 0});
                        return false;
                    }
                    if ($("#_area").val() == '') {
                        layer.msg('请选择用户地址区', {icon: 0});
                        return false;
                    }
					if ($("#addressDetail").val() == '') {
						layer.msg('服务详细地址不能为空', {icon: 0});
						return false;
					}
                }
			});


            // 判断联系电话不能为空
            $("#contact_number_").blur(function(){
                var contact_number = $("#contact_number_").val();
                if (contact_number == '') {
                    layer.msg('联系电话不能为空', {icon: 0});
                    return false;
                }
            });
			// 判断联系人不能为空
            $("#contacts_").blur(function(){
                var contacts = $("#contacts_").val();
                if (contacts == '') {
                    layer.msg('联系人不能为空', {icon: 0});
                    return false;
                }
            });
			// 判断服务详细地址不能为空
            $("#addressDetail").blur(function(){
			   var addressDetail = $("#addressDetail").val();
                if (addressDetail == '') {
                    layer.msg('服务详细地址不能为空', {icon: 0});
                    return false;
                }
			});
			// 判断费用不能为空
			$("#combo_money").blur(function(){
			   var combo_money = $("#combo_money").val();
                if (combo_money == '') {
                    layer.msg('费用不能空', {icon: 0});
                    return false;
                }
			});

			// 选择合同弹窗页面
            function openModels(type) {
                // 获取选择用户id
                var userid = $("#user_id").val();
                if (userid == '') {
                    layer.msg('请先选择用户', {icon: 0});
                    return false;
                }
                var html = '';
                html +='<div id="userh">';
                html +='<div class="modal-body">';
                html +='<h2 class="fs14 col-666 mb10">选择合同</h2>';
                html +='<p>';
                html +='<input class="modalUser-input" type="text" name="contractno" placeholder="请输入合同编号">';
                html +='<button class="btn btn-primary mr10 pl15 pr15 pt3 pb3" onclick="search_()">搜索</button>';
                html +='</p>';
                html +='<table class="table table-bordered mt20">';
                html +='<thead>';
                html +='<tr>';
                html +='<th></th>';
                html +='<th>合同编号</th>';
                html +='<th>签约合同</th>';
                html +='<th>续费周期</th>';
                html +='<th>到期时间</th>';
                html +='<th>设备台数</th>';
                html +='<th>合同金额</th>';
                html +='<th>合同状态</th>';
                html +='</tr>';
                html +='</thead>';
                html +='<tbody id="clist">';
                html +='<tr>';

                html +='<td><input type="radio" name="contractNo" value=""></td>';
                html +='<td></td>';
                html +='<td></td>';
                html +='<td></td>';
                html +='<td></td>';
                html +='<td></td>';
                html +='<td></td>';
                html +='<td></td>';
                html +='</tr>';
                html +='</tbody>';
                html +='</table>';

                html +='<div class="">';
                html +='<div class=" clearfix">';
                html +='<div class="clearfix" style="float:right;margin: 0 auto;">';
                html +='<span class="fl mt5" id="count">共0条数据</span><span id="allpage"  class="fl  mr20 mt5"></span><span  class="fl" id="AjaxPage"></span>';
                html +='</div>';
                html +='<div class="spiner-example">';
                html +='<div class="sk-spinner sk-spinner-three-bounce">';
                html +='<div class="sk-bounce1"></div>';
                html +='<div class="sk-bounce2"></div>';
                html +='<div class="sk-bounce3"></div>';
                html +='</div>';
                html +='</div>';
                html +='</div>';
                html +='</div>';
                html +='</div>';
                html +='<div class="modal-footer t_center">';
                html +='<button type="button" onclick="contractqr()" class="btn btn-primary ml30 mr30 pl20 pr20 pt3 pb3">确认</button>';
                html +='<button type="button" class="btn btn-default ml30 mr30 pl20 pr20 pt3 pb3" onclick="cancelmodel()">取消</button>';
                html +='</div>';
                html +='</div>';
                //页面层
                parent.layer.open({
                    title:'选择合同',
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['823px', '490px'], //宽高
                    content: html
                });
                Ajaxpages(1);
            }
			// 处理选择合同弹窗页面分页
            function Ajaxpages(curr) {
                // 合同编号 搜索
                var contract_no = $.trim(parent.$("input[name='contractno']").val());
                // 获取选择用户id
                var userid = $("#user_id").val();
                $.getJSON('{:url("/administrative/workorder/getcontract")}', {
                    page: curr || 1,
					userid: userid,
                    contract_no: contract_no
                }, function(data) {
                    parent.$(".spiner-example").css('display', 'none'); //数据加载完关闭动画
                    if(data == '') {
                        parent.$("#clist").html('<td colspan="20" style="padding-top:10px;padding-bottom:10px;font-size:16px;text-align:center">暂无数据</td>');
                        parent.$('#count').html("共" + 0 + "条数据");
                    } else {
                        // 字符串拼接
                        $("#clist").html('');
                        var str = '';
                        $.each(data,function(k,v){
                            str +='<tr>';
                            str +='<td><input type="radio" name="contractNo" value="'+v.contract_no+'" is_explain="'+v.is_explain+'" contract_id="'+v.contract_id+'" renew_date="'+v.renew_date+'" installed_time="'+v.installed_time+'" exire_date="'+v.exire_date+'" province="'+v.province_code+'" city="'+v.city_code+'" area="'+v.area_code+'" address="'+v.address+'"></td>';
                            str +='<td>' + v.contract_no + '</td>';
                            str +='<td>' + v.installed_time + '</td>';
                            str +='<td>' + v.renew_date + '</td>';
                            str +='<td>' + v.exire_date + '</td>';
                            str +='<td>' + v.equipmentCount + '</td>';
                            str +='<td>' + v.contract_money + '元</td>';
                            str +='<td>' + v.contract_status + '</td>';
                            str +='</tr>';
                        });
                        parent.$("#clist").html(str);

                        // 总的数据
                        parent.$('#count').html("共" + data[0].count + "条数据");
                        parent.laypage({
                            cont: parent.$('#AjaxPage'), //容器。值支持id名、原生dom对象，jquery对象,
                            pages: data[0].allPage, //总页数
                            skip: true, //是否开启跳页
                            skin: '#337ab7', //分页组件颜色
                            curr: curr || 1,
                            first: '首页', //若不显示，设置false即可
                            last: '尾页', //若不显示，设置false即可
                            groups: 3, //连续显示分页数
                            jump: function(obj, first) {
                                if(!first) {
                                    Ajaxpages(obj.curr)
                                }
                                parent.$('#allpage').html('，第' + obj.curr + '页，共' + '<i>' + obj.pages + '</i>' + '页');
								inputlength();
                            }
                        });
                    }
                });
            }



			// 选择用户弹窗页面
            function openModel(type) {
                var html = '';
                html +='<div id="userh">';
                html +='<div class="modal-body">';
                html +='<h2 class="fs14 col-666 mb10">选择用户</h2>';
                html +='<p>';
                html +='<input class="modalUser-input" type="text" name="username" placeholder="请输入用户">';
                html +='<input class="modalUser-input" type="text" name="telphone__" placeholder="请输入联系电话">';
                html +='<input class="modalUser-input" type="text" name="id_card__" placeholder="请输入身份证号码">';
                html +='<button onclick="search()" class="btn btn-primary mr10 pl15 pr15 pt3 pb3">搜索</button>';
                html +='<button class="btn btn-primary pl15 pr15 pt3 pb3" onclick="jumpcustome()"><i class="glyphicon glyphicon-plus"></i>&nbsp;&nbsp;新增用户</button>';
                html +='</p>';
                html +='<table class="table table-bordered mt20">';
                html +='<thead>';
                html +='<tr>';
                html +='<th></th>';
                html +='<th>账号</th>';
                html +='<th>户名</th>';
                html +='<th>联系人电话</th>';
                html +='<th>身份证号</th>';
                html +='<th>账号状态</th>';
                html +='</tr>';
                html +='</thead>';

                html +='<tbody id="list">';
                html +='<tr>';
//                html +='<td><input type="checkbox" name="" value=""></td>';
                html +='<td><input type="radio" name="userName" value="" ></td>';
                html +='<td></td>';
                html +='<td></td>';
                html +='<td></td>';
                html +='<td></td>';
                html +='<td></td>';
                html +='</tr>';
                html +='</tbody>';

                html +='</table>';
                html +='<div class="">';
                html +='<div class=" clearfix">';
                html +='<div class="clearfix" style="float:right;margin: 0 auto;">';
                html +='<span class="fl mt5" id="count">共0条数据</span><span id="allpage"  class="fl  mr20 mt5"></span><span  class="fl" id="AjaxPage"></span>';
                html +='</div>';
                html +='<div class="spiner-example">';
                html +='<div class="sk-spinner sk-spinner-three-bounce">';
                html +='<div class="sk-bounce1"></div>';
                html +='<div class="sk-bounce2"></div>';
                html +='<div class="sk-bounce3"></div>';
                html +='</div>';
                html +='</div>';
                html +='</div>';
                html +='</div>';
                html +='</div>';

                html +='<div class="modal-footer t_center">';
                html +='<button type="button" onclick="qwer()" class="btn btn-primary ml30 mr30 pl20 pr20 pt3 pb3">确认</button>';
                html +='<button type="button" class="btn btn-default ml30 mr30 pl20 pr20 pt3 pb3" onclick="cancelmodel()">取消</button>';
                html +='</div>';
                html +='</div>';
                //页面层
                parent.layer.open({
                    title:'选择客户',
                    type: 1,
                    skin: 'layui-layer-rim', //加上边框
                    area: ['823px', '490px'], //宽高
                    content: html
                });
                Ajaxpage(1);
            }
            // 处理选择用户弹窗页面分页
            function Ajaxpage(curr) {
                // 搜索数据
                var username = $.trim(parent.$("input[name='username']").val());  // 用户姓名
                var telphone = $.trim(parent.$("input[name='telphone__']").val()); // 联系电话
                var id_card = $.trim(parent.$("input[name='id_card__']").val());   // 身份证号
                $.getJSON('{:url("Workorder/getuser")}', {
                    page: curr || 1,
                    username: username,
                    telphone: telphone,
                    id_card: id_card
                }, function(data) {
                    console.info(data);
                    parent.$(".spiner-example").css('display', 'none'); //数据加载完关闭动画
                    if(data == '') {
                        parent.$("#list").html('<td colspan="20" style="padding-top:10px;padding-bottom:10px;font-size:16px;text-align:center">暂无数据</td>');
                        parent.$('#count').html("共" + 0 + "条数据");
                    } else {
                        // 字符串拼接
                        $("#list").html('');
                        var str = '';
                        $.each(data,function(k,v){
                            str +='<tr>';
                            str +='<td><input type="radio" name="userName" value="'+v.username+'" data="'+v.user_id+'" id_card="'+v.id_card+'" telphone="'+v.telphone+'"></td>';
//                            str +='<td><input type="checkbox" name="" value="'+v.username+'" data="'+v.user_id+'" id_card="'+v.id_card+'" telphone="'+v.telphone+'"></td>';
                            str +='<td>' + v.telphone + '</td>';
                            str +='<td>' + v.username + '</td>';
                            str +='<td>' + v.telphone + '</td>';
                            str +='<td>' + v.id_card + '</td>';
                            str +='<td>' + v.account_status + '</td>';
                            str +='</tr>';
                        });
                        // 将拼接的数据输出在页面
                        parent.$("#list").html(str);
                        // 总的数据
                        parent.$('#count').html("共" + data[0].count + "条数据");
                        parent.laypage({
                            cont: parent.$('#AjaxPage'), //容器。值支持id名、原生dom对象，jquery对象,
                            pages: data[0].allPage, //总页数
                            skip: true, //是否开启跳页
                            skin: '#337ab7', //分页组件颜色
                            curr: curr || 1,
                            first: '首页', //若不显示，设置false即可
                            last: '尾页', //若不显示，设置false即可
                            groups: 3, //连续显示分页数
                            jump: function(obj, first) {
                                if(!first) {
                                    Ajaxpage(obj.curr)
                                }
                                parent.$('#allpage').html('，第' + obj.curr + '页，共' + '<i>' + obj.pages + '</i>' + '页');
								inputlength();
                            }
                        });
                    }
                });
            }


			//重置
			function reset() {
				top.layer.confirm('你确定要重置吗?', {
					btn: ['确定', '取消'] //按钮
				}, function() {
                    $('.form-horizontal')[0].reset();
					top.layer.msg('重置成功', {icon: 1});
				});
			}

			// 初始化获取用户三级联动地址
			$(function(){
                var province = $("#_province option:selected").html();
                $("input[name='userprovince']").val(province);
                var city = $("#_city option:selected").html();
                $("input[name='usercity']").val(city);
                var area = $("#_area option:selected").html();
                $("input[name='userarea']").val(area);
			});

		    // 用户地址
            // 根据选中的省获取下面所有市
			function province_(){
                $.ajaxSettings.async = false
                $("input[name='usercity']").val('');
                $("input[name='userarea']").val('');
                var province = $("#_province option:selected").html();
                $("input[name='userprovince']").val(province);
			    var parent_id = $("#_province option:selected").attr('data');
                var str = '<option value="">--选择市--</option>';
                var str1 = '<option value="">--选择区/县--</option>';
                $("#_city").html(str);
                $("#_area").html(str1);
                // 发送ajax请求
				$.getJSON("{:url('/admin/Three/city')}",{parent_id:parent_id},function(data){
					var str = '<option value="">--选择市--</option>';
					$("#_city").html('');
					$.each(data,function(k,v){
					   str += '<option value="' + v.id + '" data="'+ v.id +'">' + v.area_name + '</option>';
					});
					$("#_city").html(str);
				});
			}
			// 根据选中的市获取下面的区县
			function city_(){
                $.ajaxSettings.async = false
                $("input[name='userarea']").val('');
                var city = $("#_city option:selected").html();
                $("input[name='usercity']").val(city);
			    var city_id = $("#_city option:selected").attr('data');
			    // 发送ajax请求
				$.getJSON("{:url('/admin/Three/areas')}",{city_id:city_id},function (data) {
					var str = '<option value="">--选择区/县--</option>';
					$("#_area").html('');
					$.each(data,function(k,v){
					    str += '<option value="' + v.id + '">' + v.area_name + '</option>';
					});
					$("#_area").html(str);
                });
			}
			// 当区县改变时
		    function area_(){
                var area = $("#_area option:selected").html();
                $("input[name='userarea']").val(area);
			}

        	function sProvince() {
		        var province = $('#sProvince').val();
		        var city=$('#sCity').val();
                console.log(province)
                var area=$('#sArea').val();
                $("#_province").find("option[value='"+province+"']").attr("selected",true).siblings().attr('selected',false);
                province_();
                $("#_city").find("option[value='"+city+"']").attr("selected",true).siblings().attr('selected',false);
                city_();
                $("#_area").find("option[value='"+area+"']").attr("selected",true).siblings().attr('selected',false);
                area_();
            }


			// 初始化获取移机三级联动地址
			$(function(){
            var province = $("#province option:selected").html();
            $("input[name='moveprovince']").val(province);
            var city = $("#city option:selected").html();
            $("input[name='movecity']").val(city);
            var area = $("#area option:selected").html();
            $("input[name='movearea']").val(area);
        });

			// 移机地址
            // 根据选中的省获取下面所有市
            function province__(){
                $("input[name='movecity']").val('');
                $("input[name='movearea']").val('');
                var province = $("#province option:selected").html();
                $("input[name='moveprovince']").val(province);
                var parent_id = $("#province option:selected").attr('data');
                var str = '<option value="">--选择市--</option>';
                var str1 = '<option value="">--选择区/县--</option>';
                $("#city").html(str);
                $("#area").html(str1);
                // 发送ajax请求
                $.getJSON("{:url('/admin/Three/city')}",{parent_id:parent_id},function(data){
                    var str = '<option value="">--选择市--</option>';
                    $("#city").html('');
                    $.each(data,function(k,v){
                        str += '<option value="' + v.id + '" data="'+ v.id +'">' + v.area_name + '</option>';
                    });
                    $("#city").html(str);
                });
            }
            // 根据选中的市获取下面的区县
            function city__(){
                $("input[name='movearea']").val('');
                var city = $("#city option:selected").html();
                $("input[name='movecity']").val(city);
                var city_id = $("#city option:selected").attr('data');
                // 发送ajax请求
                $.getJSON("{:url('/admin/Three/areas')}",{city_id:city_id},function (data) {
                    var str = '<option value="">--选择区/县--</option>';
                    $("#area").html('');
                    $.each(data,function(k,v){
                        str += '<option value="' + v.id + '">' + v.area_name + '</option>';
                    });
                    $("#area").html(str);
                });
            }
			// 当区县改变时
			function area__(){
            var area = $("#area option:selected").html();
            $("input[name='movearea']").val(area);
        }




			// 当业务类型为移机时
			function ShiftSelect(obj){
                //$("#addressDetail").val('');
			    // 当业务类型切换时，设备编号清空
                $("#equipments_number").html('');
				var txt = $(obj).val();
                if (txt == 0) {
                    layer.msg('请选择业务类型', {icon: 0});
                    return false;
                }
                // 获取合同id
                var contract_id = $("#contract_id").val();

                // 先判断合同是否为空
//                if (contract_id == '') {
                    // 合同编号为空的时候隐藏
//                    $(".ShiftCenters").hide();
//                }else{
                    // 当业务类型不为新装跟移机时
                    if(txt != 3 && txt !=5 && txt !=0){
                        // 发送ajax请求，获取装机设备跟设备编号
                        $.getJSON("{:url('/administrative/workorder/getequipments')}",{contract_id:contract_id},function(data){
                            $("#equipments_name").html('');
                            var str = '<option value="">请选择</option>';
                            $.each(data,function(k,v){
                                str += '<option value="' + v.id + '">' + v.equipments_name + '---'+ v.equipments_number +'</option>';
                            });
                            $("#equipments_name").html(str);
                        });
                        $(".ShiftCenters").show();
                        $(".ShiftCenterss").show();
                    }else{
                        $(".ShiftCenters").hide();
                        $(".ShiftCenterss").show();
                    }
//                }

                // 先判断合同是否为空
//                if (contract_id == '') {
                    // 为空的时候隐藏
//                    $(".ShiftCenter").hide();
//                }else{
                    // 业务类型为移机的时候
                    if(txt == 5){
                        // 发送ajax请求，获取装机设备跟设备编号
                        $.getJSON("{:url('/administrative/workorder/getequipments')}",{contract_id:contract_id},function(data){
                            $("#equipments_name").html('');
                            var str = '<option value="">请选择</option>';
                            $.each(data,function(k,v){
                                str += '<option value="' + v.id + '">' + v.equipments_name + '---'+ v.equipments_number +'</option>';
                            });
                            $("#equipments_name").html(str);
                        });
                        $("#combo_money").val(0);
                        //$("#addressDetail").val('');
                        $(".ShiftCenter").show();
                        $(".ShiftCenters").show();
                    }else{
                        $(".ShiftCenter").hide();
                    }
				}
//			}

			// 移机时，判断是否同一用户
			function test() {
                var isuser = $("#isuser option:selected").val();
                if(isuser == 1){
                    $(".ShiftCenterss").hide();
				}
                if (isuser == 2) {
                    $(".ShiftCenterss").show();
                }
            }

		</script>
	</body>

</html>